package cn.biao.epic.base.pojo.page;

import cn.biao.epic.core.util.HttpContext;
import cn.biao.epic.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import javax.servlet.http.HttpServletRequest;

/**
 * @Auther Uncle_Z
 * @date 2019/12/10 16:56
 * @Email:2545375@qq.com
 * @Descrition
 */
public class AntdPageFactory {

    public static Page defaultPage(){
        HttpServletRequest request = HttpContext.getRequest();

        int limit = 20;
        int page=1;
        String limitString = request.getParameter("limit");
        if (ToolUtil.isNotEmpty(limitString)) {
            limit = Integer.parseInt(limitString);
        }

        String pageString = request.getParameter("page");
        if (ToolUtil.isNotEmpty(pageString)) {
            page = Integer.parseInt(pageString);
        }

        return new Page(page, limit);
    }

    public static AntdPageInfo createPageInFo(IPage page) {
        AntdPageInfo antdPageInfo = new AntdPageInfo();
        antdPageInfo.setCount(page.getTotal());
        antdPageInfo.setData(page.getRecords());
        return antdPageInfo;
    }
}
